import {
  CallHandler,
  ExecutionContext,
  HttpStatus,
  Injectable,
  NestInterceptor,
} from "@nestjs/common";
import { Observable } from "rxjs";
import { map } from "rxjs/operators";
import { ResOp } from "../dto/ResOp.dto";

@Injectable()
export class TransformInterceptor implements NestInterceptor {
  intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
    return next.handle().pipe(
      map((data) => {
        // const response = context.switchToHttp().getResponse<FastifyReply>();
        // response.header("Content-Type", "application/json; charset=utf-8");
        return new ResOp(HttpStatus.OK, data ?? null);
      })
    );
  }
}
